local skel = fk.CreateSkill {
  name = "lb_zero__yanying",
  tags = { Skill.Limited }
}

Fk:loadTranslationTable {
  ["lb_zero__yanying"] = "焰荧",
  [":lb_zero__yanying"] = "<b>限定技</b>，出牌阶段，你可以横置两名角色，然后你对其中一名手牌数与你之差小于三的角色造成手牌数之差点火焰伤害，其余被横置角色可以先依次交给或获得其一张牌。",

  ["#lb_zero__yanying"] = "焰荧：你可以横置两名角色，然后你对其中一名手牌数与你之差小于三的角色造成手牌数之差点火焰伤害，其余被横置角色可以先依次交给或获得其一张牌",
  ["#lb_zero__yanying-choose"] = "焰荧：选择一名手牌数与你之差小于三的角色，对其造成手牌数之差点火焰伤害",
  ["#lb_zero__yanying-ask"] = "焰荧：你可以交给或获得 %src 一张牌",

  ["#lb_zero__yanying-give"] = "焰荧：交给 %src 一张牌",
  ["#lb_zero__yanying-obtian"] = "焰荧：获得 %src 一张牌",

  ["#lb_zero__yanying_give"] = "交给%src一张牌",
  ["#lb_zero__yanying_obtian"] = "获得%src一张牌",

  ["$lb_zero__yanying1"] = "我会一直烧下去！",
  ["$lb_zero__yanying2"] = "准备好迎接盛宴了吗！",
}

skel:addEffect("active", {
  prompt = "#lb_zero__yanying",
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  card_num = 0,
  target_filter = function(self, player, to_select, selected, selected_cards, card, extra_data)
    return #selected < 2 and not to_select.chained
  end,
  feasible = function(self, player, selected, selected_cards, card)
    return #selected == 2
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local tos = effect.tos
    room:sortByAction(tos)
    for _, to in ipairs(tos) do
      if to:isAlive() and not to.chained then
        to:setChainState(true)
      end
    end
    tos = table.filter(tos, function(to)
      return to:isAlive()
    end)
    local damage_tos = table.filter(tos, function(to)
      local num = to:getHandcardNum() - player:getHandcardNum()
      return math.abs(num) < 3
    end)
    if #damage_tos == 0 then return end
    local damage_to = room:askToChoosePlayers(player, {
      targets = damage_tos,
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = false,
      prompt = "#lb_zero__yanying-choose",
    })[1]
    table.removeOne(tos, damage_to)
    for _, to in ipairs(tos) do
      if damage_to.dead or player.dead then return end
      if to:isAlive() then
        local all_choices = { "#lb_zero__yanying_give:" .. damage_to.id, "#lb_zero__yanying_obtian:" .. damage_to.id,
          "Cancel" }
        local choices = {}
        if not to:isNude() then
          table.insert(choices, all_choices[1])
        end
        if not damage_to:isNude() then
          table.insert(choices, all_choices[2])
        end
        if #choices > 0 then
          table.insert(choices, "Cancel")
          local choice = room:askToChoice(to, {
            choices = choices,
            all_choices = all_choices,
            cancelable = true,
            prompt = "#lb_zero__yanying-ask:" .. damage_to.id,
            skill_name = skel.name
          })
          if table.indexOf(all_choices, choice) == 1 then
            local cards = room:askToCards(to, {
              min_num = 1,
              max_num = 1,
              skill_name = skel.name,
              cancelable = false,
              prompt = "#lb_zero__yanying-give:" .. damage_to.id,
            })
            if #cards > 0 then
              room:obtainCard(damage_to, cards, false, fk.ReasonGive, to, skel.name)
            end
          elseif table.indexOf(all_choices, choice) == 2 then
            local card = room:askToChooseCard(to, {
              target = damage_to,
              flag = "he",
              skill_name = skel.name,
              prompt = "#lb_zero__yanying-obtian:" .. damage_to.id,
            })
            room:obtainCard(to, card, false, fk.ReasonPrey, to, skel.name)
          end
        end
      end
    end
    local num = math.abs(damage_to:getHandcardNum() - player:getHandcardNum())
    if damage_to.dead or player.dead or num == 0 then return end
    room:damage {
      from = player,
      to = damage_to,
      damage = num,
      damageType = fk.FireDamage,
      skillName = skel.name,
    }
  end,
})

return skel
